var AjaxCrud = QualityCheck.AjaxCRUD;
var serverUrl = QualityCheck.GPUD.ServiceConfig;
$(function(){
	initSmPages();
	window.onresize = function () {
		initSmPages();
	};
	pagebtns();
	//getTeacherCode();
	getTeacherClasses();
});
//function getTeacherCode(){
//	var userKey = $("#user-name",parent.document).attr("key");
//	var cellphone = $("#user-name",parent.document).attr("code");
//	var data = {
//			cmd:"getTeacher",
//			model:"teacher",
//			userKey:userKey,
//			data:{
//				cellphone:cellphone
//			},
//			remark:"",
//	};
//	AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(cres){
//		if(cres.result == 1 && cres.data != undefined){
//			var teachercode = cres.data.teachercode;
//			var classcode = cres.data.classcode;
//			$("#user-name",parent.document).attr("teachercode",teachercode).attr("classcode",classcode);
//			var data = {
//					cmd:"getAllClasses",
//					model:"teacher",
//					userKey:userKey,
//					data:{
//						teachercode:teachercode
//					},
//					remark:""
//			};
//			AjaxCrud.get2(serverUrl.ServerLoginUrl,data,function(res){
//				if(res.result == 1 && res.data != undefined && res.data != ""){
//					var contents = "";
//					var list = res.data;
//					for(var i = 0; i < list.length; i++){
//						if(i == 0){
//							contents += "<div class='classes-choice classes-choice-select' classcode='"+list[i].classcode+"' grade='"+list[i].grade+"' class_='"+list[i].class_+"'>"+list[i].name+"</div>";
//						}else{
//							contents += "<div class='classes-choice' classcode='"+list[i].classcode+"' grade='"+list[i].grade+"' class_='"+list[i].class_+"'>"+list[i].name+"</div>";
//						}
//					}
//					$(".dialog-classes-contents").empty();
//					$(".dialog-classes-contents").append(contents);
//					checkUser();
//					$(".classes-choice").unbind("click");
//					$(".classes-choice").click(function(){
//						$(".classes-choice").removeClass("classes-choice-select");
//						$(this).addClass("classes-choice-select");
//					});
//				}else{
//					$(".dialog-classes-contents").empty();
//					$(".dialog-classes-contents").append("<div class='classes-choice classes-choice-select'>没有相关信息</div>");
//					checkUser();
//				}
//			},null,null);
//		}
//	},null,null);
//}
function getTeacherClasses(){
	var userKey = $("#user-name",parent.document).attr("key");
	var teachercode = $("#user-name",parent.document).attr("teachercode");
	var data = {
			cmd:"getAllClasses",
			model:"teacher",
			userKey:userKey,
			data:{
				teachercode:teachercode
			},
			remark:""
	};
	AjaxCrud.get2(serverUrl.ServerLoginUrl,data,function(res){
		if(res.result == 1 && res.data != undefined && res.data != ""){
			var contents = "";
			var list = res.data;
			for(var i = 0; i < list.length; i++){
				if(i == 0){
					contents += "<div class='classes-choice classes-choice-select' classcode='"+list[i].classcode+"' grade='"+list[i].grade+"' class_='"+list[i].class_+"' type='"+list[i].schooltype+"'>"+list[i].name+"</div>";
				}else{
					contents += "<div class='classes-choice' classcode='"+list[i].classcode+"' grade='"+list[i].grade+"' class_='"+list[i].class_+"' type='"+list[i].schooltype+"'>"+list[i].name+"</div>";
				}
			}
			$(".dialog-classes-contents").empty();
			$(".dialog-classes-contents").append(contents);
			checkUser();
			$(".classes-choice").unbind("click");
			$(".classes-choice").click(function(){
				$(".classes-choice").removeClass("classes-choice-select");
				$(this).addClass("classes-choice-select");
			});
		}else{
			$(".dialog-classes-contents").empty();
			$(".dialog-classes-contents").append("<div class='classes-choice classes-choice-select'>没有相关信息</div>");
			checkUser();
		}
	},null,null);
}
function checkUser(){
	var classcode = $("#user-name",parent.document).attr("classcode");
	if(classcode == null || classcode == "null"){
		$("#courselist-menu").hide();
		$("#courselist-op").hide();
		$("#leave-menu").hide();
		$("#leave-op").hide();
	}else{
		$("#courselist-menu").show();
		$("#leave-menu").show();
	}
	$(".dialog-display-btnshow").click(function(){
		$(".dialog-display-btnshow").hide();
		$(".dialog-display-btnhide").show();
		$(".teacher-choice-classdia").animate({right:"0px"});
	});
	$(".dialog-display-btnhide").click(function(){
		$(".dialog-display-btnshow").show();
		$(".dialog-display-btnhide").hide();
		$(".teacher-choice-classdia").animate({right:"-110px"});
	});
	changePage(PageUrl.trowofclassUrl);	
}
function pagebtns(){
	$(".left-menu").click(function(){
		$(".left-menu-sec").hide();
		$(".teacher-choice-classdia",parent.document).show();
		if($(this).attr("model") == "排课表"){
			$("#rowofclass-op").show();
			var Hei = $("#rowofclass-op .menu-sec").length * $(".menu-sec").height();
			$("#rowofclass-op").height(Hei);
			$(".teacher-choice-classdia",parent.document).hide();
		}else if($(this).attr("model") == "课程表"){
			$("#courselist-op").show();
			var Hei = $("#courselist-op .menu-sec").length * $(".menu-sec").height();
			$("#courselist-op").height(Hei);		
		}else if($(this).attr("model") == "考试"){
			$("#exam-op").show();
			var Hei = $("#exam-op .menu-sec").length * $(".menu-sec").height();
			$("#exam-op").height(Hei);
			$(".teacher-choice-classdia",parent.document).hide();
		}else if($(this).attr("model") == "考勤规则"){
			$("#attrule-op").show();
			var Hei = $("#attrule-op .menu-sec").length * $(".menu-sec").height();
			$("#attence-op").height(Hei);
		}else if($(this).attr("model") == "考勤"){
			$("#attence-op").show();
			var Hei = $("#attence-op .menu-sec").length * $(".menu-sec").height();
			$("#attence-op").height(Hei);
		}else if($(this).attr("model") == "请假"){
			$("#leave-op").show();
			var Hei = $("#leave-op .menu-sec").length * $(".menu-sec").height();
			$("#leave-op").height(Hei);
		}else if($(this).attr("model") == "通讯录"){
			$("#maillist-op").show();
			var Hei = $("#maillist-op .menu-sec").length * $(".menu-sec").height();
			$("#maillist-op").height(Hei);		
		}
	});
	$(".menu-sec").click(function(){
		var model = $(this).attr("title");
		$(".menu-sec").removeClass("menu-sec-select");
		$(this).addClass("menu-sec-select");
		$(".teacher-choice-classdia").show();
		if(model == "查看排课表"){
			changePage(PageUrl.trowofclassUrl);
			$(".teacher-choice-classdia").hide();
		}else if(model == "查看课程表"){
			changePage(PageUrl.tcourselistUrl);		
		}else if(model == "校级考试"){
			changePage(PageUrl.examUrl);
			$(".teacher-choice-classdia").hide();
		}else if(model == "班级小测"){
			changePage(PageUrl.tclassExamUrl);
			$(".teacher-choice-classdia").hide();
		}else if(model == "添加小测"){
			changePage(PageUrl.taddClassExamUrl);
			$(".teacher-choice-classdia").hide();
		}else if(model == "分配规则"){
			changePage(PageUrl.tattRuleUrl);
		}else if(model == "查看考勤"){
			changePage(PageUrl.tattenceUrl);
		}else if(model == "进校出校"){
			changePage(PageUrl.tinoutSchoolUrl);
		}else if(model == "请假管理"){
			changePage(PageUrl.tleaveUrl);
		}else if(model == "学生通讯录"){
			changePage(PageUrl.studentMaillistUrl);
		}else if(model == "老师通讯录"){
			changePage(PageUrl.teacherMaillistUrl);
		}
	});
}
function changePage(pageUrl){
	$("#right-iframe").attr("src",pageUrl);
}
function initSmPages(){
	var bodyRW = $(".index-body",parent.document).width() - $(".body-left").width()-6;
	$(".body-right").width(bodyRW);
	
	var leftCH = $(".body-left").height() - $(".left-title").height()-1;
	$(".left-content").height(leftCH);
}